<template>
  <div style="display: flex;flex-direction: column;align-items: center;margin-top: 50%">
    login<br>
    <div>
      用户名:<input type="text" v-model="userName">
    </div>
    <div>
      密&nbsp;&nbsp;码:<input type="password" v-model="password" v-on:keyup.enter="login">
    </div>
    <button @click="login">登陆</button>
  </div>
</template>

<script>
  import cookie from 'js-cookie'
  import {loginPost} from '../api/login'
  import {get} from 'lodash'
  import {Toast} from 'mint-ui';
  import {testRequest, myInterceptor} from '../util/help'
  import request from '../api/request'

  export default {
    name: "login",
    model: {},
    props: {},
    data() {
      return {
        userName: '',
        password: ''
      }
    },
    methods: {
      //这里给自己写个登陆接口
      login: function () {
        loginPost(this.userName, this.password).then((res) => {
          let token = get(res, 'data.token')
          testRequest()
          // const myInterceptor = request.interceptors.request.use(function () {
          //   console.error('i am testRequest')
          // });
          // request.interceptors.request.eject(myInterceptor);
          if (token) {
            cookie.set('token', token)
            this.$router.push('home')
          } else {
            Toast({
              message: '登陆失败',
              position: 'bottom',
              duration: 2000
            });
            this.password = ''
          }
        })
      }
    }
  }
</script>

<style scoped>

</style>
